<!-- UserLogin html file -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <!--引入css/js文件-->
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/css/login.css"></link>
    <link rel="stylesheet" href="../static/layui/css/layui.css"></link>
    <script src="../static/js/jquery.min.js"></script>
    <script src="../static/bootstrap/js/bootstrap.min.js"></script>
    <script src="../static/layui/layui.js"></script>
    <script>
      $(function(){
       //回车键进行登录
        $(document).keyup(function(e){
            if(e.keyCode == 13){
              $("#login-btn").click();
            }
        });
        //点击登录
        $("#login-btn").click(function(){
          //获取参数
         const username = $("#username").val();
         const password = $("#password").val();
         //参数验证
         if(username == null || username == ""){
           layer.alert('请先填写用户名！',{
            icon:5,
            title:"登录提示"
           });
           return;
         }
         if(password == null || password == ""){
           layer.alert('请先填写密码！',{
            icon:5,
            title:"登录提示"
           });
           return;
         }
         //用户功能
        //  获取本地上的user
         var storge = window.localStorage;
          var userList =JSON.parse(storge.getItem("user"));
          console.log(userList);
          $.each(userList,function(index,obj){
            console.log(obj);
            if(obj.username == obj.username && obj.password == password){
                window.location.href = '/index';
                return;
            }

          })
              layer.alert('用户名或者密码错误',{
            icon:5,
            title:"登录提示"
           });
           return;
        });
        $("#register-btn").click(function(){
          //跳转注册页面
          window.location.href = '/registerIndex';
        })        

      })
    </script>
</head>
<body>
<!--login登陆框-->
<div class="container login" align="center">
    <div class="control-group title_div">
     <h1 class="login-title">手写数字识别</h1>
    </div>
  <form class="form-horizontal login-form">
    <div class="control-group">
         <label for="username">用户名</label>
         <input id="username" type="text" placeholder="请输入用户名" class="input-xlarge input_username">
    </div>

    <div class="control-group" >
          <label for="password">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
          <input id="password" type="password" placeholder="请输入密码" class="input-xlarge input_password">
    </div>

     <div class="control-group">
       <button id="login-btn" type="button" class="btn btn-success login-btn">登录</button>
       <button id="register-btn" type="button" class="btn btn-info login-btn" style="margin-left:10px;">注册</button>
     </div>
  </form>
</div>
</body>
</html>